package com.shemy.fileservice.exception;

import com.shemy.fileservice.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartException;

/**
 * @Description
 * @Author Dzsom
 * @Date 2018-10-28 23:11
 * @Encoding UTF-8
 * @Version 1.0
 **/
@ControllerAdvice
@Slf4j
public class FileException {
    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public ResponseEntity<Response> handle(Exception e){
        if(e instanceof MultipartException){
            return ResponseEntity.ok().body(new Response(false,"上传文件过大"));
        }else {
            return ResponseEntity.ok().body(new Response(false,e.getMessage()));
        }

    }
}
